package com.zthz.douxing.utils

import com.zthz.douxing.command.FetchDataCommand
import com.zthz.douxing.convert.WeathPmCabinService
import org.dom4j.Element

/**
 * Created by zsw on 3/29/14.
 */
class FetchDataUtils {

    static def TYPE_WEATH = "weather"
    static def TYPE_PM25 = "pm25"

    public static getKey(Map<String,String> param){
        if(!param.type){
            return "_"+param.date+"_"+param.cityCode
        } else {
            return param.type+"_"+param.date+"_"+param.cityCode
        }
    }
    public static getKey(FetchDataCommand command){

        if(!command.type)
            return "_${command.date}_${command.cityCode}"
        else

            return "${command.type}_${command.date}_${command.cityCode}"

    }

    public static getPM25Data(List<Element> tds){


        LinkedHashMap<String,String> data  = new LinkedHashMap<String,String>();
        def mm= tds[1].element("A").attribute("href").getText() =~ /^\/city\/(.+).html$/

        data.put("pinyin",mm[0][1])
        data.put("city",tds[1].element("A").getTextTrim())
        data.put("provice",tds[2].getTextTrim())
        data.put("aqi",tds[3].getTextTrim())
        data.put("level",tds[4].getTextTrim())
        data.put("density",tds[5].getTextTrim())

        return data
    }

    public static getCambinDataKey(command){

        return WeathPmCabinService.PM_WEATHER_CABIN_KEY+"_"+command.cityCode


    }

}
